package controller
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import model.ModelManager;
	import view.graph.GraphManager;
	import view.graph.GraphStates;
	import view.graph.states.GraphExpansionType;
	import view.graph.states.GraphState;
	import view.GraphicPost;
	import view.gui.GuiManager;
	import view.ViewManager;
	/**
	 * ...
	 * @author Anthony
	 */
	public class ControllerManager
	{
		//------------------------------- statics ------------------------------\\
		private static var _self : ControllerManager = new ControllerManager();
		
		//------------------------------ variables -----------------------------\\
		private var _previousMousePosition : Point;
		
		//------------------------------ accessors -----------------------------\\
		public static function get self() : ControllerManager { return _self; }
		
		//-------------------------- public functions --------------------------\\
		public function ControllerManager()
		{
			if (_self)
				throw new Error("ControllerManager can only be accessed through ControllerManager.self");
		}
		
		public function init() : void
		{
			
		}
		
		public function onGraphStateChange(changedState : GraphState) : void
		{
			if (changedState.changeGraphicPostsGUI)
			{
				for (var graphicPostKey : String in GraphManager.self.graphGraphicPosts)
					GraphManager.self.graphGraphicPosts[graphicPostKey].unselect();
				
				GuiManager.self.updateGraphicPostGui();
			}
		}
		
		public function onOverGraphicPost(target : GraphicPost) : void
		{
			for (var targetBrotherKey : String in target.graphicAnswerOf.graphicAnswers)
			{				
				if (targetBrotherKey != target.data.key)
				{
					var targetBrother : GraphicPost = target.graphicAnswerOf.graphicAnswers[targetBrotherKey];
					targetBrother.unselect();
					
					for (var targetBrotherAnswerKey : String in targetBrother.graphicAnswers)
					{						
						targetBrother.graphicAnswers[targetBrotherAnswerKey].changeAnswersVisibility(false);
						targetBrother.graphicAnswers[targetBrotherAnswerKey].unselect();
					}
				}
			}
			
			target.changeAnswersVisibility(true, 1);
			target.select();
		}
		
		public function goToNextBrother(target : GraphicPost) : void
		{
			GraphManager.self.goToNextBrother(target);
		}
		
		public function goToPreviousBrother(target : GraphicPost) : void
		{
			GraphManager.self.goToPreviousBrother(target);
		}
		
		//------------------------- private functions --------------------------\\
		private function graphManagerMoove(coordinateName : String) : void
		{
			//var deltaX : int = (_previousMousePosition.x - e.stageX);
			//var deltaY : int = (_previousMousePosition.y - e.stageY);
			//GraphManager.self.graphic.x += deltaX;
			//GraphManager.self.graphic.y += deltaY;
			//_previousMousePosition = new Point(e.stageX, e.stageY);
		}
		
	}

}